﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using appladen.contracts;
using System.Diagnostics;

namespace appladen.host
{
    public class Host_für_DetailviewBoard : IHost_für_DetailviewBoard
    {
        internal ISet<IDetailviewBoard> bekannte_boards = new HashSet<IDetailviewBoard>();

        public event Action<IDetailviewBoard> Closed = delegate { };

        public void Process(Tuple<IDetailviewBoard, contracts.data.Datensatz> message)
        {
            var board = message.Item1;
            var daten = message.Item2;

            Trace.TraceInformation(String.Format("Host.Process(board={0}; data={1}", board, daten));

            if (!bekannte_boards.Contains(board))
            {
                board.Closed += () => { bekannte_boards.Remove(board); Closed(board); };
                bekannte_boards.Add(board);
            }

            board.Process(daten);
        }
    }
}
